# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import os
dirname=os.path.join(os.path.join(os.getcwd()),'武炼巅峰')
import re

class BiqugePipeline:
    def process_item(self, item, spider):

        return item


class BiqugetxtPipeline:

    def open_spider(self, spider):
        print('爬虫开始')

    def process_item(self, item, spider):
        re_obj=re.compile(r'[?/\\|<>*]')
        title=''.join(re_obj.split(item['title']))
        with open(os.path.join(dirname,title+'.txt'),'w') as f:
            f.write(item['content'])

    def close_spider(self, spider):
        print('爬虫结束')
